package huzh.foundation.pool.threadpool;

import huzh.foundation.pool.inf.Consumer;

/**
 *<p>title:ConsumerTie</p>
 *<p>description:</p>
 * @since 2014-5-26
 * @author huzh
 * @version 1.0
 */
public class ConsumerTie implements Runnable{
    private boolean debug = true;
    private ThreadPool threadPool = null;
    private Consumer consumer = null;

    /**
     * @param threadPool
     * @param consumer
     */
    public ConsumerTie(ThreadPool threadPool, Consumer consumer){
        this.threadPool = threadPool;
        this.consumer = consumer;
    }

    /**
     * 
     */
    public void run() {
        while (this.debug){
            Object obj = this.threadPool.getJob();
            if (obj == null){
                return;
            }
            try{
                this.consumer.doWork(obj);
            }catch (Exception e) {
                this.threadPool.debug("doWork has Exception: " + e);
            }
        }
    }
}
